package com.nikkerball.apps.darkhorse.model.evaluation.subject;

import com.nikkerball.apps.darkhorse.model.change.ChangeEvent;
import com.nikkerball.apps.darkhorse.model.change.ChangeValue;
import com.nikkerball.apps.darkhorse.model.core.Learner;
import com.nikkerball.apps.darkhorse.model.core.Subject;
import com.nikkerball.apps.darkhorse.model.evaluation.EvaluationPeriod;
import com.nikkerball.apps.darkhorse.model.evaluation.base.Evaluation;
import org.hibernate.annotations.Cascade;

import javax.persistence.*;
import java.util.List;

import static org.hibernate.annotations.CascadeType.*;

/**
 * Represents a Report Comment
 */
@Entity
@Table(name = "SubjectEvaluation")
public class SubjectEvaluation extends Evaluation {

    // ----- instance fields -----

    private String effort;

    private Subject subject;

    private List<SubjectObservation> subjectObservations;

    private List<SubjectReview> subjectReviews;

    // ----- constructors -----

    public SubjectEvaluation() {
        super();
    }

    public SubjectEvaluation(Subject subject, EvaluationPeriod evaluationPeriod, Learner learner) {
        super(evaluationPeriod, learner);
        this.subject = subject;
    }

    // ----- public methods -----

    @Transient
    public List<ChangeValue> getChangeValues(ChangeEvent changeEvent) {
        List<ChangeValue> changeValues = super.getChangeValues(changeEvent);
        changeValues.add(new ChangeValue("effort", getEffort(), changeEvent));
        return changeValues;
    }

    @Column(nullable = false)
    public String getEffort() {
        return this.effort;
    }

    public void setEffort(String effort) {
        this.effort = effort;
    }

    @ManyToOne
    @JoinColumn(name = "subject_Id", nullable = false)
    public Subject getSubject() {
        return this.subject;
    }

    public void setSubject(Subject subject) {
        this.subject = subject;
    }

    @OneToMany(mappedBy = "subjectEvaluation")
    @Cascade({MERGE, PERSIST, SAVE_UPDATE, DETACH, DELETE})
    public List<SubjectObservation> getSubjectObservations() {
        return this.subjectObservations;
    }

    public void setSubjectObservations(List<SubjectObservation> subjectObservations) {
        this.subjectObservations = subjectObservations;
    }

    @OneToMany(mappedBy = "subjectEvaluation")
    @Cascade({MERGE, PERSIST, SAVE_UPDATE, DETACH, DELETE})
    public List<SubjectReview> getSubjectReviews() {
        return this.subjectReviews;
    }

    public void setSubjectReviews(List<SubjectReview> subjectReviews) {
        this.subjectReviews = subjectReviews;
    }

}
